<%@ Control Language="C#" AutoEventWireup="true" CodeFile="URLSecurityInput.ascx.cs" Inherits="admin_webparts_URLSecurity_URLSecurityInput" %>
<%@ Import Namespace="NTTHAO.CommonWeb" %> 
<%@ Import Namespace="NTTHAO.Common.BL" %> 

<script type="text/javascript">

NTTHAO.namespace('page');

NTTHAO.page.langText = [];
NTTHAO.page.langText['BLANK_URL'] = '<%=LanguageUtility.GetLanguageText("BLANK_URL", Session)%>';
NTTHAO.page.langText['ERROR_MESSAGE'] = '<%=this._ErrorMessage %>';

NTTHAO.page.userAllow = new Array();
//NTTHAO.page.userAllow[NTTHAO.page.userAllow.length] = {id: 1, name: 'abc'};
<%if(this._UrlMap != null) {
      URLSecurity[] listSecurity = this._UrlMap.GetAllUserPermission(this._UrlMap.ID);%>
    <%if(listSecurity != null) for (int i = 0; i < listSecurity.Length; i++)
      {%>
      NTTHAO.page.userAllow[NTTHAO.page.userAllow.length] = {userid: <%=listSecurity[i].UserID %>, allow: <%=listSecurity[i].AllowRequest %>};
      <% } %>
<%} %>


function validateSubmit() {
    var txtURL = document.getElementById("<%=txtURL.ClientID %>");
    
    var errorMessage = "";
    
    errorMessage = CheckFieldString("noblank", txtURL, NTTHAO.page.langText['BLANK_URL']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        txtURL.select();
        txtURL.focus();
        return false;
    }
    
    return true;
}

function doSubmit(  ) {
    if(!validateSubmit()) {
        return false;
    }
    
    return true;
}

function doCheckAll(o) {
    var objUsers = document.getElementsByName("chkUser");
    if(objUsers && objUsers.length) {
        for(var i = 0; i < objUsers.length; i++) {
            objUsers[i].checked = o.checked;
        }
    } else if(objUsers) {
        objUsers.checked = o.checked;
    }
}

function doCheck() {
    var objAll = document.getElementById("chkAll");
    var objUsers = document.getElementsByName("chkUser");
    
    var allCheck = true;

    if(objUsers && objUsers.length) {
        for(var i = 0; i < objUsers.length; i++) {
            if(!objUsers[i].checked) {
                allCheck = false;
                break;
            }
        }
        objAll.checked = allCheck;
    } else if(objUsers) {
        objAll.checked = objUsers.checked;
    }
}

YAHOO.util.Event.onDOMReady(function() {
    var objUrlID = document.getElementById("<%=urlID.ClientID %>");
    if(objUrlID.value.length < 1) {
        var objAll = document.getElementById("chkAll");
        objAll.checked = true;
        doCheckAll(objAll);
    } else {
        //var objUsers = document.getElementsByName("chkUser");
        for(var i = 0; i < NTTHAO.page.userAllow.length; i++) {
            var objUser = document.getElementById('chkUser_' + NTTHAO.page.userAllow[i].userid);
            if(objUser != null) {
                objUser.checked = NTTHAO.page.userAllow[i].allow > 0 ? true : false;
            }
        }
        doCheck();
    }
});
</script>


<div class="tip">
    <h1><%=LanguageUtility.GetLanguageText("URL_AUTHORITY", Session)%></h1>
</div>
<form id="URLSecurity" runat="server" onsubmit="return doSubmit();">
<input type="hidden" id="urlID" name="urlID" value="" runat="server"/>
<p style="text-align: left;">
    <span id="spSave" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><input id="btnCancel1" type="button" value="<%=LanguageUtility.GetLanguageText("CANCEL", Session)%>" onclick="javscript: location.href='?type=user&action=list';" /></span></span>
</p>
<table cellspacing="0" cellpadding="0" border="1" class="grid" style="margin: 10px auto;">
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("URL", Session)%>:
        </td>
        <td>
            <asp:TextBox ID="txtURL" runat="server" Width="300px"></asp:TextBox></td>
    </tr>
    <tr class="odd">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("DESCRIPTION", Session)%>:</td>
        <td>
            <asp:TextBox ID="txtDescription" runat="server" Width="300px"></asp:TextBox></td>
    </tr>
    <tr class="even" style="display: <%=this._LoggedUser.UserName.Equals("admin", StringComparison.OrdinalIgnoreCase) ? "" : "none" %>;">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("EDITABLE", Session)%>:</td>
        <td>
            <input id="chkEditable" type="checkbox" checked="checked" runat="server" /></td>
    </tr>
    <tr class="odd">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("ADMIN_USER", Session)%>:</td>
        <td>
            <%if (this._UserList != null) {%>
            <table cellspacing="0" cellpadding="0" border="1" class="grid" style="width: auto;">
                <tr class="even">
                    <td>
                        <input type="checkbox" id="chkAll" name="chkUserAll" value="-1" onclick="doCheckAll(this);" />
                    </td>
                    <td align="left" style="width: 150px;"><label for="chkAll"><b><%=LanguageUtility.GetLanguageText("CHECK_ALL", Session) %></b></label></td>
                </tr>
                <%for (int i = 0; i < this._UserList.Rows.Count; i++)
                  {
                      if ((AdminUser.ADMIN_TYPE != (byte)this._UserList.Rows[i][AdminUser.TYPE__COLUMN_NAME]))
                      {%>
                <tr class="odd">
                    <td>
                        <input type="checkbox" id="chkUser_<%=this._UserList.Rows[i][AdminUser.ID__COLUMN_NAME] %>" name="chkUser" value="<%=this._UserList.Rows[i][AdminUser.ID__COLUMN_NAME] %>" onclick="doCheck();" />
                    </td>
                    <td align="left"><label for="chkUser_<%=this._UserList.Rows[i][AdminUser.ID__COLUMN_NAME] %>"><%=this._UserList.Rows[i][AdminUser.USERNAME__COLUMN_NAME]%></label></td>
                </tr>
                <%}
              } %>
            </table>
            <%} %>
        </td>
    </tr>
</table>
<p style="text-align: left;">
    <span id="spSave2" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave2" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel2" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><input id="btnCancel2" type="button" value="<%=LanguageUtility.GetLanguageText("CANCEL", Session)%>" onclick="javscript: location.href='?type=user&action=list';" /></span></span>
</p>
</form>
<style type="text/css">
    #spCancel1, #spSave, #spCancel2, #spSave2 {font-size:1.1em; font-weight: bold; }
    #spCancel1 button, #spSave button, #spCancel2 button, #spSave2 button { font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: bold; }
</style>
<script type="text/javascript"> 
YAHOO.util.Event.onContentReady("spCancel1", function () {
    var spCancel1 = new YAHOO.widget.Button("spCancel1");
    spCancel1.on("click", function () {location.href='?type=ser&action=list';}); 
});
YAHOO.util.Event.onContentReady("spCancel2", function () {
    var spCancel2 = new YAHOO.widget.Button("spCancel2");
    spCancel2.on("click", function () {location.href='?type=ser&action=list';}); 
});
YAHOO.util.Event.onContentReady("spSave", function () {
    var spSave = new YAHOO.widget.Button("spSave");
});
YAHOO.util.Event.onContentReady("spSave2", function () {
    var btnSave2 = new YAHOO.widget.Button("spSave2");
});

YAHOO.util.Event.onDOMReady(function() {
    document.getElementById("<%=txtURL.ClientID %>").select();
    document.getElementById("<%=txtURL.ClientID %>").focus();
});

if(NTTHAO.page.langText['ERROR_MESSAGE'] != '') {
    YAHOO.util.Event.onDOMReady(function() {
        alert(NTTHAO.page.langText['ERROR_MESSAGE']);
    });
}
</script>